package vista;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;


public class JuegoNoIniciado extends JDialog implements ActionListener {
	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();

	
	public JuegoNoIniciado() {
		setTitle("Partida no iniciada");
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setIconImage(new ImageIcon("iconos/ayuda.png").getImage());
		setBounds(200, 200, 300, 120);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setLayout(new FlowLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		JLabel mensaje = new JLabel("Debe iniciar una nueva partida.");
		mensaje.setFont(new Font("Tahoma", Font.BOLD, 16));
		contentPanel.add(mensaje, BorderLayout.CENTER);
		
		JButton okButton = botonConAccionEnter("OK");
		okButton.setActionCommand("OK");		
		
		okButton.addActionListener(this);
		contentPanel.add(okButton, BorderLayout.SOUTH);		
				
	}
	
	 public void actionPerformed(ActionEvent evt) {
		    String comando = evt.getActionCommand();
		    if (comando == "OK") {
		    	this.dispose();
		    }
	 }
	 
	 private JButton botonConAccionEnter(String etiqueta) {
		 JButton boton = new JButton(etiqueta);
			
			boton.registerKeyboardAction(boton.getActionForKeyStroke(
	                KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false)),
	                KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false),
	                JComponent.WHEN_FOCUSED);
			
			boton.registerKeyboardAction(boton.getActionForKeyStroke(
	                KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true)),
	                KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true),
	                JComponent.WHEN_FOCUSED);
			 return boton;
	 }	 
	
}
